﻿using B.S.SmartStorPro.Domain;
using Microsoft.EntityFrameworkCore;
using Mysqlx.Crud;
using SqlSugar;

namespace B.S.SmartStorPro.Infrastructure
{
    public class WmsDbContext
    {
        public SqlSugarClient Db { get; }

        public WmsDbContext(string connectionString)
        {
            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = connectionString,
                DbType = DbType.MySql,
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute
            });

            // 初始化数据库和表
            Db.DbMaintenance.CreateDatabase();
            Db.CodeFirst.InitTables(
                typeof(AvailableInventory),
                typeof(CarrierManagement),
                typeof(CategoryInfo),
                typeof(Customers),
                typeof(Departments),
                typeof(DispatchManagement),
                typeof(DocumentTypes),
                typeof(Equipment),
                typeof(FinancialCategories),
                typeof(FinancialRecords),
                typeof(Inbound),
                typeof(InitialInventory),
                typeof(Inventory),
                typeof(InventoryAlerts),
                typeof(InventoryCounts),
                typeof(InventoryList),
                typeof(lnventoryLedger),
                typeof(Locations),
                typeof(LossReports),
                typeof(MessageCenter),
                typeof(Orders),
                typeof(Outbound),
                typeof(Payables),
                typeof(Permissions),
                typeof(ProductCategories),
                typeof(ProductManagement),
                typeof(Products),
                typeof(PurchaseOrders),
                typeof(Receivables),
                typeof(ReturnManagement),
                typeof(Roles),
                typeof(SalesManagement),
                typeof(SalesReturns),
                typeof(Suppliers),
                typeof(Transfers),
                typeof(UnitManagement),
                typeof(Users),
                typeof(Warehouses)
            );
        }
    }
}
